<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
	pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@taglib uri="/struts-tags" prefix="s"%>
<script type="text/javascript" charset="utf-8"
	src="js/jquery.listnav.min-2.1.js"></script>
<script type="text/javascript" charset="utf-8"
	src="js/jquery.dataTables.listnav.js"></script>
<script type="text/javascript" charset="utf-8">
	$(document).ready(function() {
		var organisationId = getURLParameter("organisationId");
		var oTable = $('#directorates-table').dataTable({
			"sDom" : 'Zrtp',
			"sPaginationType" : "bootstrap",
			"iDisplayLength" : 15,
			"bServerSide" : true,
			"bPaginate" : true,
			"sAjaxSource" : "directorateAjaxTable.action",
			"aoSearchCols": [
				 				null,
				 				null,
				 				null,
				 				null,
				 				{"sSearch": "Yes"}
				 			],
			"aoColumnDefs" : [ {
				"fnRender" : function(o, val) {
					
					if(o.aData[4] == "Yes"){
						return '<a href=editDirectorate.action?directorateId=' 
								+ o.aData[5]
								+ '&organisationId='
								+ organisationId
								+ '>' 
								+ o.aData[0] 
								+ '</a>';
					}
					else{
						return '<a href="#" onClick=toActive(' + o.aData[5] + ')>' + o.aData[0] + '</a>';
					}
				},
				"aTargets" : [ 0 ]
			} ],
			"fnServerParams": function ( aoData ) {
				var organisationId = getURLParameter("organisationId");
		  		aoData.push( { "name": "organisationId", "value": organisationId});
			}
		});

		$('#check-active').click(function() {
			var other = $('#check-active:checked').val();
			if (other != undefined) {
				oTable.fnFilter("", 4, true, false);
			} else {
				oTable.fnFilter("Yes", 4, true, false);
			}
		});		
	});
	function toActive(id) {
		var r = confirm('Do you want to make this Directorate active?');
		if (r == true) {
			window.location.replace("activeDirectorate.action?directorateId=" + id);
		}
	}
	
	function getURLParameter(name) {
	    return decodeURI(
	        (RegExp(name + '=' + '(.+?)(&|$)').exec(location.search)||[,null])[1]
	    );
	}
	console.log("organisationId: " + getURLParameter("organisationId"));
</script>
<div class="tab-pane" id="directorate">
	<div class="">
		<div class="">
			<div class="row-fluid">	
						<div id="directorates">
							<form action="#" class='form-horizontal' method="post">
							<%-- <input type="hidden" id="organisationId" name="organisationId" value='<s:property value="organisationId"/>'/> --%>
								<div class="control-group"></div>
								<div class="control-group">
									<div id="inactive-div">
										<a href="addDirectorate.action?organisationId=<s:property value="organisationId"/>" class="btn btn-success">Create</a> <label
											class="checkbox"><input type="checkbox"
											name="check-inactive" id="check-active"> Include
											In-active</label>
									</div>
									<table id="directorates-table"
										class="table table-striped dataTable table-bordered display">
										<thead>
											<tr>
												<th>BU/Directorates Name</th>
												<th>Office Address Line 1</th>
												<th>Postcode</th>
												<th>Contact</th>
												<th>Is Active?</th>
											</tr>
										</thead>
										<tbody>
										</tbody>
									</table>
								</div>
							</form>
						</div>
					</div>
				</div>
		</div>
</div>
